package com.sjz.han.industry.activites;

import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sjz.han.industry.R;
import com.sjz.han.industry.base.BaseActivity;
import com.sjz.han.industry.entities.LoignEntity;
import com.sjz.han.industry.entities.PersonEntity;
import com.sjz.han.industry.entities.WaitJhMemberDetailEntity;
import com.sjz.han.industry.internetmanage.ReqestUrl;
import com.sjz.han.industry.utils.JsonUtils;
import com.sjz.han.industry.utils.LiveDataBus;
import com.sjz.han.industry.utils.PicUtils;
import com.sjz.han.industry.utils.ToastUtils;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import okhttp3.Call;

//带激活会员详情
public class WaitJhMemberDetailActivity extends BaseActivity implements View.OnClickListener{
    private String userId="";
    private Button jhxq_sure_btn;

    private ImageView djh_jtu_img,jhxq_photo_img;
    private TextView jhxq_name_tv,jhxq_time_tv,jhxq_phone_tv,jhxq_bankname_tv,jhxq_bankcode_tv;
    @Override
    protected int setLayoutId() {
        return R.layout.activity_waitjhmemberdetail;
    }

    @Override
    protected void initDatas() {
        userId=getIntent().getStringExtra("userid");
         getMsg();
    }

    @Override
    protected void initViews() {
        reback_btn=(RelativeLayout)this.findViewById(R.id.reback_btn);
        titleTv=(TextView)this.findViewById(R.id.ctitle_tv);
        titleTv.setText("会员激活");

        djh_jtu_img=(ImageView)this.findViewById(R.id.djh_jtu_img);
        jhxq_sure_btn=(Button)this.findViewById(R.id.jhxq_sure_btn);
        jhxq_photo_img=(ImageView)this.findViewById(R.id.jhxq_photo_img);
        jhxq_name_tv=(TextView)this.findViewById(R.id.jhxq_name_tv);
        jhxq_time_tv=(TextView)this.findViewById(R.id.jhxq_time_tv);
        jhxq_phone_tv=(TextView)this.findViewById(R.id.jhxq_phone_tv);
        jhxq_bankname_tv=(TextView)this.findViewById(R.id.jhxq_bankname_tv);
        jhxq_bankcode_tv=(TextView)this.findViewById(R.id.jhxq_bankcode_tv);

    }

    @Override
    protected void setLisener() {
        reback_btn.setOnClickListener(this);
        djh_jtu_img.setOnClickListener(this);
        jhxq_sure_btn.setOnClickListener(this);
    }

    @Override
    protected void onRetry() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.reback_btn:
                finish();
                break;
            case R.id.djh_jtu_img:
                startActivity(new Intent(this,ShowBigImageActivity.class));
                break;
            case R.id.jhxq_sure_btn:
                action();
                break;
        }
    }

    public void getMsg(){
        OkHttpUtils
                .post()
                .url(ReqestUrl.DJH_HYDTAIL_URL)
                .addParams("token",shareUtils.getToken())
                .addParams("userId",userId)
                .tag(this)
                .build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                ToastUtils.popUpToast("请求超时");
            }
            @Override
            public void onResponse(String response, int id) {
                if(ReqestUrl.rebacRequestJson(response)!=null){
                    WaitJhMemberDetailEntity entity= JsonUtils.getObject(response,WaitJhMemberDetailEntity.class);
                    if(entity!=null&&entity.code==0&&entity.data!=null){
                        jhxq_name_tv.setText(entity.data.username);
                                jhxq_time_tv.setText("提交时间："+entity.data.createTime);
                                jhxq_phone_tv.setText(entity.data.phone);
                                jhxq_bankname_tv.setText(entity.data.bankName);
                                jhxq_bankcode_tv.setText(entity.data.bankCode);
                        PicUtils.showImageViewToCircle(WaitJhMemberDetailActivity.this, R.mipmap.ic_wd_tx, ReqestUrl.BASE+entity.data.photo, jhxq_photo_img);
                        if(!TextUtils.isEmpty(entity.data.moneyPhoto)){
                                    PicUtils.showImg(WaitJhMemberDetailActivity.this,djh_jtu_img,ReqestUrl.BASE+entity.data.moneyPhoto);
                                }
                    }else{
                        ToastUtils.popUpToast(entity.msg);
                    }
                }
            }
        });
    }
    public void action(){
        showLoadingDialog("正在激活");
        OkHttpUtils
                .post()
                .url(ReqestUrl.DJH_HY_JH_URL)
                .addParams("token",shareUtils.getToken())
                .addParams("userId",userId)
                .tag(this)
                .build().execute(new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                hideLoadingDialog();
                ToastUtils.popUpToast("请求超时");
            }
            @Override
            public void onResponse(String response, int id) {
                hideLoadingDialog();
                if(ReqestUrl.rebacRequestJson(response)!=null){
                    LoignEntity entity= JsonUtils.getObject(response,LoignEntity.class);
                    if(entity!=null&&entity.code==0){
                        LiveDataBus.get().with("Userid").setValue(userId);
                        ToastUtils.popUpToast("激活成功!");
                         finish();
                    }else{
                        ToastUtils.popUpToast(entity.msg);
                    }
                }
            }
        });
    }
}
